package org.hawk.gwt.ppc.parser.impl;

import java.util.Iterator;
import java.util.List;

import org.hawk.gwt.ppc.parser.Descriptor;
import org.hawk.gwt.ppc.parser.DescriptorContainer;
import org.hawk.gwt.ppc.parser.DescriptorIndexOutOfBoundException;

/**
 * Abstract implementation of container that holds other descriptors.
 * 
 * @author alex.bereznevatiy@gmail.com
 *
 */
abstract class AbstractDescriptorContainer 
		extends AbstractDescriptor implements DescriptorContainer {
	private List<Descriptor> descriptors;
	
	AbstractDescriptorContainer(List<Descriptor> descriptors) {
		this.descriptors = descriptors;
		for (Descriptor descriptor : this.descriptors) {
			if (descriptor instanceof AbstractDescriptor) {
				((AbstractDescriptor)descriptor).setParent(this);
			}
		}
	}

	public Iterator<Descriptor> iterator() {
		return descriptors.iterator();
	}

	public Descriptor get(int index) throws DescriptorIndexOutOfBoundException {
		return descriptors.get(index);
	}

	public Descriptor remove(int index)
			throws DescriptorIndexOutOfBoundException {
		return descriptors.remove(index);
	}

	public int size() {
		return descriptors.size();
	}
	
}
